home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / amag / AM9404_2.lha / tips & tricks / setprefs.asm < prev    next >
Assembly Source File  |  1994-02-28  |  3KB  |  160 lines

  1. ; --- Includes laden (Pfad individuell setzen)! ---
  2.     INCDIR  maxon:include/
  3.     INCLUDE exec/memory.i
  4.     INCLUDE exec/exec_lib.i
  5.     INCLUDE dos/dos.i
  6.     INCLUDE dos/dos_lib.i
  7.     INCLUDE intuition/preferences.i
  8.     INCLUDE intuition/intuition_lib.i
  9.  
  10. ; Individueller Startup-Code, muß jedoch in
  11. ; D1 Flag setzen, wegen Unterscheidung von
  12. ; CLI/WB ( D1=TRUE->WB ; D1=FALSE->CLI )
  13.  
  14.     INCLUDE startup.asm
  15.  
  16.     RSRESET
  17.  
  18. prefBuff    rs.l    1
  19. DosBase     rs.l    1
  20. IntBase     rs.l    1
  21. FileH       rs.l    1
  22.  
  23. SIZE    equ __RS
  24.  
  25.  
  26. Begin
  27.     tst.l   d1  ;kommen wir vom CLI?
  28.     bne     Error_NULL  ;nein -> Fehler
  29.     subq    #1,d0
  30.     lea     FileName(pc),a1
  31.  
  32. .loop1
  33.     cmp.b   #" ",(a0)   ;führende Spaces überlesen
  34.     bne.s   .tstfil
  35.     lea     1(a0),a0
  36.     dbf     d0,.loop1
  37.  
  38. .tstfil
  39.     move.b  (a0),(a1)+  ;Filenamen
  40.     cmp.b   #" ",(a0)   ;holen
  41.     beq.s   .getfil
  42.     cmp.b   #$0a,(a0)+
  43.     beq.s   .getfil
  44.     dbf     d0,.tstfil
  45.  
  46. .getfil
  47.     clr.b   -(a1)   ;Nullbyte!
  48.     lea     -SIZE(sp),sp
  49.     move.l  sp,a5
  50.  
  51.     ; Libraries öffnen
  52.     lea     IntName(pc),a1
  53.     moveq   #34,d0
  54.     move.l  $4.w,a6
  55.     jsr     _LVOOpenLibrary(a6)
  56.  
  57.     move.l  d0,IntBase(a5)
  58.     bne.s   .OpenDos
  59.     move.l  #$38004,d7
  60.     bra     ExitAlert
  61.  
  62. .OpenDos
  63.     lea     DosName(pc),a1
  64.     moveq   #34,d0
  65.     jsr     _LVOOpenLibrary(a6)
  66.  
  67.     move.l  d0,DosBase(a5)
  68.     bne.s   .AllocMem
  69.     move.l  #$38007,d7
  70.     bra     ExitAlert
  71.  
  72.     ; Speicher für Pref-Strukt reservieren
  73.  
  74. .AllocMem
  75.     move.l  #pf_SIZEOF,d0
  76.     move.l  #MEMF_PUBLIC+MEMF_CLEAR,d1
  77.     jsr     _LVOAllocMem(a6)
  78.     move.l  d0,prefBuff(a5)
  79.     bne.s   OpenFilename
  80.     move.l  #$10000,d7
  81.     bra     ExitAlert
  82.  
  83.     ; Das File öffnen und einlesen
  84.  
  85. OpenFilename
  86.     lea     FileName(pc),a0
  87.     move.l  a0,d1
  88.     move.l  #MODE_OLDFILE,d2
  89.     move.l  DosBase(a5),a6
  90.     jsr     _LVOOpen(a6)
  91.     move.l  d0,FileH(a5)
  92.     bne.s   LoadPref
  93.     move.l  #$60007,d7
  94.     bra ExitAlert
  95.  
  96. LoadPref    move.l  d0,d1
  97.     move.l  prefBuff(a5),d2
  98.     move.l  #pf_SIZEOF,d3
  99.     jsr     _LVORead(a6)
  100.  
  101.     move.l  prefBuff(a5),a0
  102.     move.l  #pf_SIZEOF,d0
  103.     moveq   #0,d1   ;FALSE, keine INFO
  104.     move.l  IntBase(a5),a6
  105.     jsr     _LVOSetPrefs(a6)
  106.  
  107. Ende    moveq   #0,d7   ;AlertFlag löschen
  108.  
  109.     ; Resourcen freigeben und auf ReturnFlag achten
  110.  
  111. ExitAlert   move.l  FileH(a5),d1
  112.     beq.s   .freemem
  113.     move.l  DosBase(a5),a6
  114.     jsr     _LVOClose(a6)
  115.  
  116. .freemem    move.l  prefBuff(a5),d0
  117.     beq.s   .closeDos
  118.     move.l  d0,a1
  119.     move.l  #pf_SIZEOF,d0
  120.     move.l  $4.w,a6
  121.     jsr     _LVOFreeMem(a6)
  122.  
  123. .closeDos   move.l  DosBase(a5),d0
  124.     beq.s   .closeInt
  125.     move.l  d0,a1
  126.     move.l  $4.w,a6
  127.     jsr     _LVOCloseLibrary(a6)
  128.  
  129. .closeInt   move.l  IntBase(a5),d0
  130.     beq.s   .tstAlert
  131.     move.l  d0,a1
  132.     move.l  $4.w,a6
  133.     jsr     _LVOCloseLibrary(a6)
  134.  
  135.     ; Alert aus Exec ausgeben, falls Fehler aufgetreten sind
  136.  
  137. .tstAlert   tst.l   d7
  138.     beq.s   .weg
  139.     lea     AlertParams(pc),a5
  140.     move.l  $4.w,a6
  141.     jsr     _LVOAlert(a6)
  142.  
  143. .weg    lea SIZE(sp),sp ;Stack korrigieren!
  144.  
  145. Error_NULL  moveq   #0,d0
  146.     rts
  147.  
  148. AlertParams dc.l    -1,-1
  149.  
  150. ;*** Namen und Strings ***
  151. IntName dc.b    "intuition.library",0
  152.     even
  153. DosName dc.b    "dos.library",0
  154.     even
  155. VersionsString  dc.b    "$VER: SetPrefs V1.0 (24.01.94)"
  156.     even
  157. ;*** Puffer ***
  158. FileName    ds.b    50
  159.  
  160.